package com.example.isak.myasd.common.dao;

import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface GeneratorMapper {
	/**
	 * 查询当前数据库连接下的所有表信息（包含表明、表单存储引擎、表单备注、表单创建时间）
	 * @return
	 */
	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
			+ " where table_schema = (select database())")
	List<Map<String, Object>> list();

	/**
	 * 查询当前数据库连接下的表单数量
	 * @param map
	 * @return
	 */
	@Select("select count(*) from information_schema.tables where table_schema = (select database())")
	int count(Map<String, Object> map);

	/**
	 * 根据表名查询表单信息（包含表明、表单存储引擎、表单备注、表单创建时间）
	 * @param tableName
	 * @return
	 */
	@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
			+ "	where table_schema = (select database()) and table_name = #{tableName}")
	Map<String, String> get(String tableName);


	/**
	 * 根据表名查询表单的所有字段信息（字段名称、字段类型、字段备注、主键信息和字段额外信息）
	 * @param tableName
	 * @return
	 */
	@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
			+ " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
	List<Map<String, String>> listColumns(String tableName);
}
